package com.acwing.partition1;

import java.io.*;
import java.util.Arrays;

public class AC10有依赖的背包问题 {

    private static final int N = 110;
    private static int[] h = new int[N], e = new int[N], ne = new int[N], hv = new int[N], hw = new int[N];
    private static int[][] f = new int[N][N];
    private static int n, m, idx = 0;

    private static StreamTokenizer tokenizer = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    private static PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        n = nextInt(); m = nextInt();
        Arrays.fill(h, -1);
        int root = -1;
        for (int i = 1; i <= n; i++) {
            hv[i] = nextInt(); hw[i] = nextInt();
            int p = nextInt();
            if (p == -1) root = i;
            else add(p, i);
        }
        dfs(root);
        writer.println(f[root][m]);
        writer.flush();
    }

    private static void dfs(int u) {
        for (int i = h[u]; i != -1; i = ne[i]) {
            int v = e[i];
            dfs(v);
            for (int j = m - hv[u]; j >= 0; j--) {
                for (int k = 0; k <= j; k++) {
                    f[u][j] = Math.max(f[u][j], f[u][j - k] + f[v][k]);
                }
            }
        }
        for (int i = m; i >= hv[u]; i--) f[u][i] = f[u][i - hv[u]] + hw[u];
        for (int i = 0; i < hv[u]; i++) f[u][i] = 0;
    }

    private static void add(int a, int b) {
        e[idx] = b;
        ne[idx] = h[a];
        h[a] = idx++;
    }

    private static int nextInt() throws IOException {
        tokenizer.nextToken();
        return (int) tokenizer.nval;
    }
}
